using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Betarium.PotonEditor
{
	public class ToolInfoLine : ToolInfo
	{
		bool m_bMove;
		public ToolInfoLine(EditViewForm form)
			: base(form)
		{
		}
		public override void OnMouseDown(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseDown(sender, e);
			if (e.Button == MouseButtons.Left)
			{
				m_bMove = true;
			}
		}
		public override void OnMouseUp(object sender, MouseEventArgs e)
		{
			bool bMouseLeftDown = m_Form.SelectState.MouseLeftDown;
			m_bMove &= bMouseLeftDown;
			m_Form.SelectState.OnMouseUp(sender, e);
			if (m_bMove && bMouseLeftDown && e.Button == MouseButtons.Left)
			{
				if(m_Form.SelectState.MouseBeginPos != m_Form.SelectState.MouseCurrentPos)
				{
                    this.m_Form.AddUndo();
                    Graphics graph = Graphics.FromImage(m_Form.Image);
					graph.DrawLine(new Pen(m_Form.PaintState.MainColor), m_Form.SelectState.MouseBeginPos, m_Form.SelectState.MouseCurrentPos);
					graph.Dispose();
					SetModified();
				}
			}
			m_bMove = false;
//			m_MovePos = Point.Empty;
		}
		public override void OnMouseMove(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseMove(sender, e);
			m_bMove &= m_Form.SelectState.MouseLeftDown;
//			Point mouseMoveBefore = m_Form.Selection.MouseBeforePos;
//			Point cursorPos = m_Form.Selection.MouseCurrentPos;
//			Point mouseMoveBegin = m_Form.Selection.MouseBeginPos;
			if (m_bMove && m_Form.SelectState.MouseLeftDown)
			{
				/*
				Point selectSize = cursorPos;
				selectSize.Offset(-mouseMoveBegin.X, -mouseMoveBegin.Y);
				Point selectBegin = mouseMoveBegin;
				if (selectSize.X < 0)
				{
					selectSize.X = -selectSize.X;
					selectBegin.X = mouseMoveBegin.X - selectSize.X;
				}
				if (selectSize.Y < 0)
				{
					selectSize.Y = -selectSize.Y;
					selectBegin.Y = mouseMoveBegin.Y - selectSize.Y;
				}
				*/
//				m_MovePos = cursorPos;
//				m_Rect = new Rectangle(selectBegin, new Size(selectSize));
				m_Form.Cursor = Cursors.Cross;
			}
			else
			{
				m_Form.Cursor = Cursors.Arrow;
			}
		}
		public override void OnPaint(object sender, PaintEventArgs e)
		{
			if (m_Form.SelectState.MouseLeftDown)
			{
				if (m_Form.SelectState.MouseBeginPos != m_Form.SelectState.MouseCurrentPos)
				{
					e.Graphics.DrawLine(new Pen(m_Form.PaintState.MainColor), m_Form.SelectState.MouseBeginPos, m_Form.SelectState.MouseCurrentPos);
				}
			}
		}
	}
}
